﻿using S7Project_One.Views;
using System.Configuration;
using System.Data;
using System.Windows; 

namespace S7Project_One
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        private const string MutexName = "ManSui_Application";
        private static Mutex _mutex;
        protected override void OnStartup(StartupEventArgs e)
        {

            bool createdNew;
            _mutex = new Mutex(true, MutexName, out createdNew);
            if (!createdNew)
            {
                // 如果互斥锁已存在，说明程序已运行
                MessageBox.Show("程序已在运行中, 请勿重复启动!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
                Current.Shutdown(); // 关闭当前实例
                return;
            }

            base.OnStartup(e);
            new MainWindow().ShowDialog();
            //ShutdownMode = "OnExplicitShutdown" 关闭窗口但是不管应用 app.xaml上设置
            Application.Current.Shutdown();
        }
        protected override void OnExit(ExitEventArgs e)
        {
 
            _mutex?.Dispose();
            base.OnExit(e);
        }
    }

}
